<style>
    .layui-input-block {
        margin-left: 78px;
        min-height: 36px;
    }
    .lay-query-box .query-lt {
        width: 75%;
    }
</style>
<!-- 正文开始 -->
<div class="open-form">
    <div class="open-model">
        <div class="open-auto">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">工序类型：</label>
                                    <div class="layui-input-block">
                                        <select id="processType1" name="processType1" lay-filter="processType1"
                                                class="common-select-search">
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">工序性质：</label>
                                    <div class="layui-input-block">
                                        <select id="processNature1" name="processNature1" lay-filter="processNature1"
                                                class="common-select-search">
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">节点名称：</label>
                                    <div class="layui-input-block">
                                        <input id="processName1" name="processName1" class="layui-input" type="text"
                                               placeholder="请输入节点名称"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" id="processSearchABtn" lay-filter="processSearchABtn"
                                            lay-submit>查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" id="processResets" type="button" lay-filter="processResets"
                                            lay-submit>重置
                                    </button>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="processAddTable" lay-filter="processAddTable"></table>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="processAddSubmit" lay-submit>保存</button>
        </div>
    </div>
</div>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin',], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;


        admin.getDictList("processType1", "process_node_type", null, "工序类型");
        admin.getDictList("processNature1", "process_nature", null, "工序性质");

        let templateId = admin.getTempData("processTemplateDataId");

        let processAddTab = table.render({
            elem: '#processAddTable',
            url: config.base + 'enterprise/product/admin/processLineTemplate/listAndProcess?type=2&templateId=' + templateId,
            cellMinWidth: 100,
            page: true,
            cols: [[
                {type: 'checkbox'}
                , {
                    field: 'nodeCodes',
                    align: 'center',
                    title: '节点编码',
                }
                , {field: 'nodeNames', align: 'center', title: '节点名称'}
                , {field: 'nodeTypesName', align: 'center', title: '节点类型'}
                , {field: 'processNatureName', align: 'center', title: '工序性质'}
                , {
                    field: 'qualityIf', align: 'center', title: '是否支持委外', templet: function (d) {
                        return d.qualityIf === '0' ? '是' : '否';
                    }
                }
                , {field: 'qualityRateName', align: 'center', title: '检验频率'}
                , {
                    field: 'processWarehouseIf',
                    align: 'center',
                    title: '创建工序仓',
                    templet: function (d) {
                        return d.qualityIf === '0' ? '是' : '否';
                    }
                }
                , {field: 'statusName', align: 'center', title: '状态', width: 180}
            ]],
            done: function (res, curr, count) {
            }
        });

        form.on('submit(processSearchABtn)', function (data) {
            data.field.processType = $("#processType1").val();
            data.field.processNature = $("#processNature1").val();
            data.field.processName = $("#processName1").val();
            processAddTab.reload({where: data.field}, 'data');
        });

        // 重置搜索
        form.on('submit(processResets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            processAddTab.reload({where: field, page: {curr: 1}}, 'data');
        });

        //确认选择的点击事件
        form.on('submit(processAddSubmit)', function (d) {
            var checkRows = table.checkStatus('processAddTable');
            var ids = [];
            checkRows.data.forEach(item => {
                ids.push(item.id);
            })
            d.field.processLineTemplateId = templateId;
            d.field.processIds = ids;
            admin.req('enterprise/product/admin/processLineTemplateRecord/add', d.field, function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    table.reload('processTable');
                    layer.close(parentData.zindex);
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'POST');
            return false;
        });

    });
</script>